Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic

Public MustInherit Class WrapperBase
   Private mAttributes As Attributes

   Public Overridable Function IDString() As String
      Return Me.GetType.Name
   End Function

   Private Function GetAttributes() As Attributes
      If mAttributes Is Nothing Then
         mAttributes = New Attributes
      End If
      Return mAttributes
   End Function

   Public ReadOnly Property Attributes() As Attributes
      Get
         Return mAttributes
      End Get
   End Property

   Public Sub AddCustomAttribute( _
            ByVal namespaceUri As String, _
            ByVal namespacePrefix As String, _
            ByVal name As String, _
            ByVal value As String)
      GetAttributes().Add(New Attribute(namespaceUri, namespacePrefix, name, value))
   End Sub

   Public Sub AddCustomAttribute( _
            ByVal attribute As KadGen.MetadataWrapper.Attribute, _
            ByVal overwriteValue As Boolean)
      Dim attributes As Attributes = GetAttributes()
      Dim oldAttribute As Attribute = attributes.GetItem( _
               attribute.NamespaceUri, attribute.NamespacePrefix, attribute.Name)
      If oldAttribute Is Nothing Then
         ' Explicitly create clone
         attributes.Add(New Attribute(attribute.NamespaceUri, attribute.NamespacePrefix, attribute.Name, attribute.Value))
      Else
         If overwriteValue Then
            oldAttribute.Value = attribute.Value
            ' Else no op
         End If
      End If
   End Sub

End Class
